package nc.bs.ic.ic2a1bj;

import java.math.BigDecimal;

import nc.bs.dao.BaseDAO;
import nc.bs.dao.DAOException;
import nc.jdbc.framework.processor.ArrayProcessor;
import nc.ui.pub.bill.BillStatus;
import nc.vo.pub.lang.UFDouble;

public class SunNumBO {

	private BaseDAO dao =null;
	
	private BaseDAO getBaseDAO(){
		if(dao == null)
			dao = new BaseDAO();
		return dao;
	}
	
	public Object[] getNnum(String vbatchcode,String cinventoryid,Object coderid ){
		StringBuffer  strb = new StringBuffer();
		strb.append(" select sum(nvl(b.nnumber,0)),sum(nvl(b.npacknumber,0))  from so_sale e join so_saleorder_b b on e.csaleid = b.csaleid  where nvl(e.dr,0)=0 and nvl(b.dr,0)=0 ");
		
		if(getString_TrimZeroLenAsNull(vbatchcode) !=null)
			strb.append(" and b.cbatchid = '"+vbatchcode+"'");
		
		if(getString_TrimZeroLenAsNull(cinventoryid) !=null)
			strb.append(" and b.cinventoryid  = '"+cinventoryid+"'");
		
		if(getString_TrimZeroLenAsNull(coderid) !=null)
			strb.append(" and b.corder_bid  <> '"+coderid+"'");
		
		strb.append(" and  e.fstatus  in ("+BillStatus.FREE+","+BillStatus.AUDITING+")");
		
		Object o =null;
		try {
			o = getBaseDAO().executeQuery(strb.toString(),new ArrayProcessor());
		} catch (DAOException e) {
			e.printStackTrace();
		}
		
		if(o == null)
			return null;
		
		Object[] os = (Object[])o;
		
		return os;
	}
	
	public  String getString_TrimZeroLenAsNull(Object value) {
		  if ( value==null || value.toString().trim().length()==0 ) {
		    return  null ;
		  }
		  return  value.toString() ;
		}
	
	public static UFDouble getUFDouble_NullAsZero(Object  value) {
		  if ( value == null || value.toString().trim().equals("") ){
		    return  nc.vo.scm.pu.VariableConst.ZERO ;
		  }else if(value  instanceof  UFDouble){
		    return  (UFDouble)value ;
		  }else if(value  instanceof  BigDecimal){
		    return  new UFDouble((BigDecimal)value) ;
		  }else{
		    return  new UFDouble(value.toString().trim());
		  }
		}
}
